﻿// <copyright file="TestEventLog.cs" company="Microsoft Corporation">
// Copyright (c) 2009 Microsoft Corporation All Rights Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2009-10-17</date>
// <summary>TestEventLog class definition</summary>

namespace Test
{
    using System.IO.IsolatedStorage;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Microsoft.WebAnalytics;

    /// <summary>
    /// Test the <see cref="Microsoft.WebAnalytics.EventLog"/> class.
    /// </summary>
    [TestClass]
    public class TestEventLog
    {
        /// <summary>
        /// Test storing the data for the application
        /// </summary>
        [TestMethod]
        public void TestApplicationScope()
        {
            var eventLog = new EventLog("TestEventLog.txt", Scope.Application);

            eventLog.WriteEntry(new AnalyticsEvent() { Name = "Hello World" });
            eventLog.WriteEntry(new AnalyticsEvent() { Name = "Hello Silverlight" });

            eventLog.WriteLog();

            var file = IsolatedStorageFile.GetUserStoreForApplication();

            if (file.FileExists("TestEventLog.txt"))
            {
                file.DeleteFile("TestEventLog.txt");
            }
        }

        /// <summary>
        /// Test storing the data for the site
        /// </summary>
        [TestMethod]
        public void TestSiteScope()
        {
            var eventLog = new EventLog("TestEventLog.txt", Scope.Site);

            eventLog.WriteEntry(new AnalyticsEvent() { Name = "Hello World" });
            eventLog.WriteEntry(new AnalyticsEvent() { Name = "Hello Silverlight" });

            eventLog.WriteLog();

            var file = IsolatedStorageFile.GetUserStoreForSite();

            if (file.FileExists("TestEventLog.txt"))
            {
                file.DeleteFile("TestEventLog.txt");
            }
        }
    }
}
